//
//  ShareResouceDetailFooterView.m
//  ShangHaiHuDongApp
//
//  Created by 刘应平 on 2017/6/22.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ShareResouceDetailFooterView.h"
#import "STPhotoBroswer.h"
@interface ShareResouceDetailFooterView ()
/** 简介  */
@property (strong, nonatomic) UILabel  *jianjie;
/**  content  */
@property (strong, nonatomic) UILabel  *content;
/**  预约  */
@property (strong, nonatomic) UIButton  *sendButton;
/**  针对资源类型是面向组织的，非书记身份提示  */
@property (strong, nonatomic) UILabel  *tishiLabel;


@end
/**  180  */
@implementation ShareResouceDetailFooterView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.sendButton];
        self.sendButton.sd_layout
        .bottomSpaceToView(self, 40 * [UIScreen zj_screenHScale])
        .heightIs(50 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self, 40 * [UIScreen zj_screenWScale])
        .rightSpaceToView(self, 40 * [UIScreen zj_screenWScale]);
        [self addSubview:self.jianjie];
        self.jianjie.sd_layout
        .topSpaceToView(self, 15 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self, 20 * [UIScreen zj_screenWScale])
        .heightIs(15 * [UIScreen zj_screenHScale])
        .widthIs(100);
        
        [self addSubview:self.content];
        
        
//        [self addSubview:self.tishiLabel];
//        self.tishiLabel.sd_layout
//        .topSpaceToView(self.sendButton, 10 * [UIScreen zj_screenHScale])
//        .leftEqualToView(self.sendButton)
//        .rightEqualToView(self.sendButton)
//        .heightIs(15 * [UIScreen zj_screenHScale]);
//        
        
    }
    return self;
}


- (void)clickButton{
    if (self.delegate) {
        [self.delegate ShareResouceDetailFootertap_click];
    }

}
- (void)setIsNoShow:(BOOL)isNoShow{
    _isNoShow = isNoShow;
    if (isNoShow) {
        self.sendButton.hidden = YES;
    }else{
        if ([self.TORANGE isEqualToString:@"1"]) {
            if (!ZJUSERINFORMODEL.isSecretary) {
                self.tishiLabel.hidden = NO;
                [self.sendButton setTitleColor:[UIColor textBlackColor] forState:UIControlStateNormal];
                self.sendButton.backgroundColor = [UIColor themeGrayColor];
                self.sendButton.userInteractionEnabled = NO;
            }else{
                self.tishiLabel.hidden = YES;
            }
           
        }else{
            self.tishiLabel.hidden = YES;
        }
    }
}

- (void)setContentString:(NSString *)contentString{
    _contentString = contentString;
    self.content.attributedText = [UILabel setSpaceForLineWithText:contentString lineSpace:4 * [UIScreen zj_screenHScale]];
    self.content.sd_layout
    .topSpaceToView(self.jianjie, 15 * [UIScreen zj_screenHScale])
    .leftSpaceToView(self, 20 * [UIScreen zj_screenWScale])
    .rightSpaceToView(self, 20 * [UIScreen zj_screenWScale])
    .heightIs(self.height);
}


- (void)setImages:(NSArray *)images{
    _images = images;
    CGFloat width = ([UIScreen zj_screenWith] - 70 * [UIScreen zj_screenWScale]) / 4;
    for (int i = 0; i < images.count; i ++) {
        UIImageView *imageView = [UIImageView new];
        imageView.userInteractionEnabled = YES;
        [imageView sd_setImageWithURL:CREATEURL(images[i][@"FILE_PATH"]) placeholderImage:PlaceholderImage];
        imageView.contentMode = UIViewContentModeScaleToFill;
        imageView.tag = i;
        NSInteger yu = i % 4;
        NSInteger zheng = i / 4;
        imageView.frame = CGRectMake(20 * [UIScreen zj_screenWScale] + (width + 10 * [UIScreen zj_screenWScale]) * yu, self.height + 55 * [UIScreen zj_screenHScale] + (width + [UIScreen zj_screenHScale]) * zheng, width, width);
        [self addSubview:imageView];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView:)];
        [imageView addGestureRecognizer:tap];
    }
}

- (void)setIsJFDH:(BOOL)isJFDH{
    _isJFDH = isJFDH;
    if (isJFDH) {
        [self.sendButton setTitle:@"兑换" forState:UIControlStateNormal];
    }
}

- (void)tapImageView:(UITapGestureRecognizer *)tap{
    STPhotoBroswer *brower = [[STPhotoBroswer alloc] initWithFrame:CGRectMake(0, 0, [UIScreen zj_screenWith], [UIScreen zj_screenHeight]) ImageArray:self.images currentIndex:tap.view.tag];
    [brower show];

}
- (UILabel *)jianjie{
    if (!_jianjie) {
        _jianjie = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor textBlackColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(17);
            label.text = @"简介: ";
            label;
        });
    }
    return _jianjie;
}

- (UILabel *)content{
    if (!_content) {
        _content = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.numberOfLines = 0;
            label.textColor = [UIColor textGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(15);
            label;
        });
    }
    return _content;
}

- (UILabel *)tishiLabel{
    if (!_tishiLabel) {
        _tishiLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentCenter;
            label.text = @"注：该资源个人身份不能预约";
            label.textColor = [UIColor zj_colorWithHexString:@"f24141"];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(14);
            label;
        });
    }
    return _tishiLabel;
}



- (UIButton *)sendButton{
    if (!_sendButton) {
        _sendButton = ({
            UIButton *button = [[UIButton alloc] init];
            [button setTitle:@"预约资源" forState:UIControlStateNormal];
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            button.titleLabel.textAlignment = NSTextAlignmentCenter;
            button.titleLabel.font = LYPFONT(15);
            button.backgroundColor = [UIColor themeColor];
            [button addTarget:self action:@selector(clickButton) forControlEvents:UIControlEventTouchUpInside];
            button.layer.cornerRadius = 3;
            button.layer.masksToBounds = YES;
            button;
            
        });
    }
    return _sendButton;
}

@end
